/*
Copyright (c) [2019年5月1日] [吴超]
[MBT_studio] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
#pragma once

#include "底层绘图/intern/Vulkan/Vulkan框架.h"
#include "底层绘图/intern/Vulkan/线管/着色器.h"




struct S_Vk线管 : public S_管线 {
	VkDevice		m_设备;
	//VkRenderPass	m_渲染通道;

	VkPipelineCache m_线管缓存;
	
	std::vector<VkDescriptorSet>	m_DS;

	
	S_Vk线管(S_设备环境& 环境, std::string name);
	~S_Vk线管();

	void f_创建线管(const S_线管创建参数& 参数, S_着色& shader, E_管线槽 槽);
	void f_bind(const S_推送常量& push) override ;
};






struct S_Vk计算线管 : public S_管线 {
	VkDevice		m_设备;

	VkPipelineCache m_线管缓存;
	//VkPipeline		m_线管;

	S_Vk计算线管(S_设备环境& 环境, std::string name);
	~S_Vk计算线管();

	void f_创建线管(S_着色& shader) override ;
	
};







struct S_Vk光追线管 : public S_管线 {
	VkPipeline		m_线管;
	S_Vk着色*		m_着色;
	VkPipelineLayout	m_线管布局;

	std::vector<VkDescriptorSetLayout>		m_参数布局;

	S_Vk光追线管(S_设备环境& ctx, std::string name);

	void f_创建线管(const S_线管创建参数& 参数, S_着色& shader) {}
	void f_创建线管(const S_着色器创建配置& 参数, S_着色& shader);
	void f_重置线管();
	void f_销毁线管();

	void f_销毁着色器(uint32 id);
};




VkPipeline f_pipeline_创建(S_Vk着色* 着色, VkPipelineLayout 线管布局, S_设备环境& ctx);



template<E_管线槽 线管槽>
void f_pipeline_绑定管线(VkCommandBuffer 命令缓存, S_材质管线* 材质) {
	//vkCmdBindPipeline(命令缓存, VK_PIPELINE_BIND_POINT_GRAPHICS, (*(S_Vk线管*)材质->m_着色线管->m_Pipeline).m_线管);

	VkPipeline pipeline;
	if constexpr (线管槽 == E_管线槽::e_阴影渲染) {
		pipeline = (VkPipeline)((*(S_Vk线管*)材质->m_阴影着色线管->m_Pipeline).m_线管);
	} 
	else if constexpr (线管槽 == E_管线槽::e_环境渲染) {
		pipeline = (VkPipeline)((*(S_Vk线管*)材质->m_环境着色线管->m_Pipeline).m_线管);
	}
	else if constexpr (线管槽 == E_管线槽::e_几何渲染) {
		pipeline = (VkPipeline)((*(S_Vk线管*)材质->m_几何着色线管->m_Pipeline).m_线管);
	}
	else if constexpr (线管槽 == E_管线槽::e_UI渲染) {
		pipeline = (VkPipeline)((*(S_Vk线管*)材质->m_UI渲染线管->m_Pipeline).m_线管);
	}
	else if constexpr (线管槽 == E_管线槽::e_UI合成) {
		pipeline = (VkPipeline)((*(S_Vk线管*)材质->m_UI合成线管->m_Pipeline).m_线管);
	}
	else if constexpr (线管槽 == E_管线槽::e_颜色渲染) {
		pipeline = (VkPipeline)((*(S_Vk线管*)材质->m_着色线管->m_Pipeline).m_线管);
	}
	vkCmdBindPipeline(命令缓存, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
}

Inline S_Vk着色* f_pipeline_绑定管线(VkCommandBuffer 命令缓存, S_材质管线* 材质, const E_管线槽 管线槽) {
	S_Vk着色* shader = nullptr;
	VkPipeline pipeline{};
	if (管线槽 == E_管线槽::e_阴影渲染) {
		pipeline = (VkPipeline)((*(S_Vk线管*)材质->m_阴影着色线管->m_Pipeline).m_线管);
		shader = (S_Vk着色*)材质->m_阴影着色线管->m_Shader;
	} 
	else if (管线槽 == E_管线槽::e_环境渲染) {
		pipeline = (VkPipeline)((*(S_Vk线管*)材质->m_环境着色线管->m_Pipeline).m_线管);
		shader = (S_Vk着色*)材质->m_环境着色线管->m_Shader;
	}
	else if (管线槽 == E_管线槽::e_几何渲染) {
		pipeline = (VkPipeline)((*(S_Vk线管*)材质->m_几何着色线管->m_Pipeline).m_线管);
		shader = (S_Vk着色*)材质->m_几何着色线管->m_Shader;
	}
	else if (管线槽 == E_管线槽::e_UI渲染) {
		pipeline = (VkPipeline)((*(S_Vk线管*)材质->m_UI渲染线管->m_Pipeline).m_线管);
		shader = (S_Vk着色*)材质->m_UI渲染线管->m_Shader;
	}
	else if (管线槽 == E_管线槽::e_UI合成) {
		pipeline = (VkPipeline)((*(S_Vk线管*)材质->m_UI合成线管->m_Pipeline).m_线管);
		shader = (S_Vk着色*)材质->m_UI合成线管->m_Shader;
	}
	else if (管线槽 == E_管线槽::e_颜色渲染) {
		pipeline = (VkPipeline)((*(S_Vk线管*)材质->m_着色线管->m_Pipeline).m_线管);
		shader = (S_Vk着色*)材质->m_着色线管->m_Shader;
	}
	vkCmdBindPipeline(命令缓存, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
	return shader;
}

//Inline void f_pipeline_绑定渲染管线(VkCommandBuffer 命令缓存, S_材质管线* 材质, const E_管线槽 管线槽) {
//	VkPipeline pipeline{};
//	if (管线槽 == E_管线槽::e_阴影渲染) {
//		pipeline = (VkPipeline)((*(S_Vk线管*)材质->m_阴影着色线管->m_Pipeline).m_线管);
//		shader = (S_Vk着色*)材质->m_阴影着色线管->m_Shader;
//	} 
//	else if (管线槽 == E_管线槽::e_环境渲染) {
//		pipeline = (VkPipeline)((*(S_Vk线管*)材质->m_环境着色线管->m_Pipeline).m_线管);
//		shader = (S_Vk着色*)材质->m_环境着色线管->m_Shader;
//	}
//	else if (管线槽 == E_管线槽::e_几何渲染) {
//		pipeline = (VkPipeline)((*(S_Vk线管*)材质->m_几何着色线管->m_Pipeline).m_线管);
//		shader = (S_Vk着色*)材质->m_几何着色线管->m_Shader;
//	}
//	else if (管线槽 == E_管线槽::e_UI渲染) {
//		pipeline = (VkPipeline)((*(S_Vk线管*)材质->m_UI渲染线管->m_Pipeline).m_线管);
//		shader = (S_Vk着色*)材质->m_UI渲染线管->m_Shader;
//	}
//	else if (管线槽 == E_管线槽::e_UI合成) {
//		pipeline = (VkPipeline)((*(S_Vk线管*)材质->m_UI合成线管->m_Pipeline).m_线管);
//		shader = (S_Vk着色*)材质->m_UI合成线管->m_Shader;
//	}
//	else if (管线槽 == E_管线槽::e_颜色渲染) {
//		pipeline = (VkPipeline)((*(S_Vk线管*)材质->m_着色线管->m_Pipeline).m_线管);
//		shader = (S_Vk着色*)材质->m_着色线管->m_Shader;
//	}
//}



